﻿/*
 * 2012  - C.B.S. - Compute Software Solutions
 * This file is part of Observation Log.
 * 
 *     Observation Log is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     Observation Log is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with Observation Log.  If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Drawing;
using System.Windows.Forms;

namespace ObservationLog
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }

        /// <summary>
        /// Returns a section with the given size of the full sky chart centered on the requested coordinates.
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="RAHour"></param>
        /// <param name="RAMinute"></param>
        /// <param name="DecDeg"></param>
        /// <param name="DecMinute"></param>
        /// <returns></returns>
        public static Image GetChartImage(int width, int height, int RAHour, float RAMinute, int DecDeg, float DecMinute)
        {
            Bitmap chart = Properties.Resources.Chart; //Full sky map
            Image destImg = new Bitmap(width, height); //new image to return

            //Determines where the given RA coordinate will be located on the full chart - in pixels
            float RaPixels = (chart.Width - ((RAHour * 60) + RAMinute) * (chart.Width / 1440f)) - (width / 2);
            
            //Determines where the given DEC coordinate will be located on the full chart - in pixels
            float DecPixels = ((5400 - ((DecDeg * 60) + DecMinute)) * (chart.Height / 10800f)) - (height / 2);
            
            Graphics g = Graphics.FromImage(destImg);
            g.DrawImage(chart, 
                new RectangleF(0, 0, width, height), 
                new RectangleF(RaPixels, DecPixels, width, height), 
                GraphicsUnit.Pixel);
            g.Dispose();
            return destImg;
        }
    }
}
